import { ResponseTask, TaskType } from '@entities/Tasks'
import { useUpdateTaskStatusMutation } from '@shared/api'
import { Button } from '@shared/ui/Button'
import { MouseEvent, memo } from 'react'

interface TaskDoneButtonProps {
  task: ResponseTask
}
export const TaskDoneButton = memo(({ task }: TaskDoneButtonProps) => {
  const [updateTask] = useUpdateTaskStatusMutation()
  const handleSubmit = (e: MouseEvent) => {
    updateTask({ ...task, type: TaskType.COMPLETED })
    e.stopPropagation()
  }
  return <Button circle color='success' iconName='check' onClick={handleSubmit} size='small' />
})

TaskDoneButton.displayName = 'TaskDoneButton'
